//从localStorage根据key取值
function getLocal(key) {
  return localStorage.getItem(key);
}

//localStorage设值
function setLocal(key, val) {
  localStorage.setItem(key, val);
}

//localStorage根据key取json信息
function getLocalJson(key) {
  return JSON.parse(localStorage.getItem(key))
}

//localstorage的json设值
function setLocalJson(key, jsonVal) {
  localStorage.setItem(key, JSON.stringify(jsonVal))
}

//从SessionStorage根据key取值
function getSession(key) {
  return sessionStorage.getItem(key);
}

//SessionStorage设值
function setSession(key, val) {
  sessionStorage.setItem(key, val)
}

//sessionStorage根据key取json信息
function getSessionJson(key) {
  return JSON.parse(sessionStorage.getItem(key))
}

//sessionStorage的json设值
function setSessionJson(key, jsonVal) {
  sessionStorage.setItem(key, JSON.stringify(jsonVal))
}

function removeLocalKey(key) {
  localStorage.removeItem(key);
}

function removeSessionKey(key) {
  sessionStorage.removeItem(key)
}

function clearLocal() {
  localStorage.clear()
}

function clearSession() {
  sessionStorage.clear()
}

const map = {
  getLocal,
  getLocalJson,
  getSession,
  getSessionJson,
  setLocal,
  setLocalJson,
  setSession,
  setSessionJson,
  removeLocalKey,
  removeSessionKey,
  clearLocal,
  clearSession
};

export default map
